// npm i vue-router
import Vue from 'vue'
import VueRouter from 'vue-router'
// 注册路由
Vue.use(VueRouter)
// 配置路由
const router = new VueRouter({
    routes: [
        {
            path: '/',
            redirect: '/login',  // 重定向:重新指向其它path,会改变网址
        },
        {
            path: '/login',
            name:'login',
            component:()=> import('@/components/login')
        },
        {
            path: '/dashboard',
            name:'dashboard',
            redirect: '/hmEachrts',  // 重定向:重新指向其它path,会改变网址
            component:()=> import('@/views/dashboard'),
            children:[{
                path: '/hmEachrts',
                name:'hmEachrts',
                component:()=> import('@/views/hmEachrts')
            },
            {
                path: '/heimaMsg',
                name:'heimaMsg',
                component:()=> import('@/views/heimaMsg')
            },
        ],
        },

     
    ],
})
import { getToken } from "@/utils/token";
router.beforeEach((to, from, next) => {
    let token = getToken()
    if (token) {
        if (to.path=='/login') {
            next(
                {
                    name:'dashboard'
                }
            )
        }
    }else{
        if (to.path=='/login') {
            next()
        }
    }
    next()
  })
export default router
